package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TProcure;
import com.ruoyi.system.service.ITProcureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购信息Controller
 * 
 * @author 张倍
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/system/procure")
public class TProcureController extends BaseController
{
    @Autowired
    private ITProcureService tProcureService;

    /**
     * 查询采购信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:procure:list')")
    @GetMapping("/list")
    public TableDataInfo list(TProcure tProcure)
    {
        startPage();
        List<TProcure> list = tProcureService.selectTProcureList(tProcure);
        return getDataTable(list);
    }

    /**
     * 导出采购信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:procure:export')")
    @Log(title = "采购信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TProcure tProcure)
    {
        List<TProcure> list = tProcureService.selectTProcureList(tProcure);
        ExcelUtil<TProcure> util = new ExcelUtil<TProcure>(TProcure.class);
        util.exportExcel(response, list, "采购信息数据");
    }

    /**
     * 获取采购信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:procure:query')")
    @GetMapping(value = "/{ordersId}")
    public AjaxResult getInfo(@PathVariable("ordersId") Integer ordersId)
    {
        return success(tProcureService.selectTProcureByOrdersId(ordersId));
    }

    /**
     * 新增采购信息
     */
    @PreAuthorize("@ss.hasPermi('system:procure:add')")
    @Log(title = "采购信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProcure tProcure)
    {
        return toAjax(tProcureService.insertTProcure(tProcure));
    }

    /**
     * 修改采购信息
     */
    @PreAuthorize("@ss.hasPermi('system:procure:edit')")
    @Log(title = "采购信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProcure tProcure)
    {
        return toAjax(tProcureService.updateTProcure(tProcure));
    }

    /**
     * 删除采购信息
     */
    @PreAuthorize("@ss.hasPermi('system:procure:remove')")
    @Log(title = "采购信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ordersIds}")
    public AjaxResult remove(@PathVariable Integer[] ordersIds)
    {
        return toAjax(tProcureService.deleteTProcureByOrdersIds(ordersIds));
    }
}
